//
//  RightTableViewCell.m
//  MemoryTravel
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 fcx. All rights reserved.
//

#import "RightTableViewCell.h"

@implementation RightTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        [self createSubViews];
    }

    return self;
}

- (void)createSubViews{

    self.contentView.backgroundColor = [UIColor colorWithRed:230 / 255.0 green:236 / 255.0 blue:242 / 255.0 alpha:1.0];

    self.headerImage = [UIImageView new];
    self.headerImage.layer.masksToBounds = YES;//裁掉边界
    self.headerImage.layer.cornerRadius = 5;//设置半径
    [self.contentView addSubview:self.headerImage];
    self.headerImage.contentMode = UIViewContentModeScaleAspectFill;

    [self.headerImage mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(10);
        make.top.mas_equalTo(5);
        make.width.mas_equalTo(Width - 20);
        make.height.equalTo(self.contentView.mas_height).offset(-10);
    }];

    self.namelabel = [UILabel new];
    self.namelabel.numberOfLines = 0;
    self.namelabel.font = [UIFont systemFontOfSize:30];
    self.namelabel.textColor = [UIColor whiteColor];
    self.namelabel.textAlignment = NSTextAlignmentRight;
    self.namelabel.layer.masksToBounds = YES;//裁掉边界
    self.namelabel.layer.cornerRadius = 5;//设置半径
    [self.contentView addSubview:self.namelabel];

    [self.namelabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(20);
        make.bottom.mas_equalTo(-40);
    }];

    self.titleLabel = [UILabel new];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.layer.masksToBounds = YES;//裁掉边界
    self.titleLabel.layer.cornerRadius = 5;//设置半径
    [self.contentView addSubview:self.titleLabel];

    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(20);
        make.bottom.mas_equalTo(-20);
    }];

    //渐变
    self.gradientLayer = [CAGradientLayer layer];
    self.gradientLayer.frame = CGRectMake(0, 100, Width, 100);
    [self.headerImage.layer addSublayer:self.gradientLayer];

    //设置渐变颜色方向
    self.gradientLayer.startPoint = CGPointMake(0, 0);

    self.gradientLayer.endPoint = CGPointMake(0, 1);
    //设定颜色组
    self.gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor,
                                  (__bridge id)[UIColor blackColor].CGColor];

    //设定颜色分割点
    self.gradientLayer.locations = @[@(0.1f) ,@(1.0f)];
}

- (void)setRightModel:(RightModel *)rightModel{

    _rightModel = rightModel;

    //图片
    NSURL *urlHeader = [NSURL URLWithString:rightModel.image_url];

    [self.headerImage sd_setImageWithURL:urlHeader placeholderImage:[UIImage imageNamed:@"placeHoderImage.png"]];

    self.namelabel.text = rightModel.name;
    
    self.titleLabel.text = rightModel.title;
}

@end
